//    Copyright (C) Kherty.  All rights reserved.
using System;
using OpenLS.Spreadsheet.Expressions;

namespace OpenLS.Spreadsheet.Formats.Biff.Tokens
{
    internal class UnaryToken : EmptyFormulaToken
    {
        private readonly UnaryOperatorType _operator;

        public UnaryToken(UnaryOperatorType op)
        {
            _operator = op;
        }


        internal override Expression GetExpression(FormulaEvaluationContext context)
        {
            FormulaToken t2 = context.PoppedArgument();
            Expression left = t2.GetExpression(context);
            return new PrefixUnaryExpression(_operator, left);
        }

        public override FormulaTokenId TokenId
        {
            get {
                switch (_operator)
                {
                        case UnaryOperatorType.Add:
                        return FormulaTokenId.Uplus;
                        case UnaryOperatorType.Subtract:
                        return FormulaTokenId.Uminus;
                    default: throw new NotSupportedException();
                } 
            }
        }
    }
}